import axios from 'axios';
var api = {};
const baseURL = '/api';
// const baseURL = 'http://192.168.10.6:3000';
// const baseURL = 'http://192.168.1.111:3000';

axios.interceptors.request.use((config) => {
  return new Promise((resolve, reject) => {
    resolve(config)
  });
}, (error) => {
});

axios.interceptors.response.use((response) => {
  return new Promise((resolve, reject) => {
    resolve(response);
  })
}, (error) => {
});

api.initHeader = function () {
  // var userToken = utils.getCookie("userToken");
  // if (userToken) {
  //   axios.defaults.headers.common['token'] = userToken;
  // }
}

// 文件上传
api.commonUpload = function (data) {
  var url = baseURL + '/common/upload';
  var formFile = new FormData();
  formFile.append("files", data);
  return axios.post(url, formFile, {
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  });
}

// 用户登录
api.userLogin = function (data) {
  var url = baseURL + '/user/login';
  return axios.post(url, data);
}

// 用户注册
api.userRegister = function(data) {
  var url = baseURL + '/user/register';
  return axios.post(url, data);
}

// 完善用户信息
api.userUpdateUserInfo = function(data) {
  var url = baseURL + '/user/updateUserInfo';
  return axios.post(url, data);
}

// 查找用户
api.userFindUserDetail = function(data) {
  var url = baseURL + '/user/findUserDetail';
  return axios.post(url, data);
}

// 聊天好友列表
api.chatList = function (data) {
  var url = baseURL + '/chat/list';
  return axios.post(url, data);
}
// 聊天好友添加
api.chatAdd = function (data) {
  var url = baseURL + '/chat/add';
  return axios.post(url, data);
}
// 聊天好友删除
api.chatDelete = function(data) {
  var url = baseURL + '/chat/delete';
  return axios.post(url, data);
}
// 聊天详情
api.chatDetail = function (data) {
  var url = baseURL + '/chat/detail';
  return axios.post(url, data);
}

//添加聊天信息
api.addChatInfoDetail = function (data) {
  var url = baseURL + '/chat/add/detail';
  return axios.post(url, data);
}

// 好友列表
api.friendList = function (data) {
  var url = baseURL + '/friend/list';
  return axios.post(url, data);
}

// 好友添加
api.friendAdd = function(data) {
  var url = baseURL + '/friend/add';
  return axios.post(url, data);
}

// 好友申请新增
api.friendApply = function(data) {
  var url = baseURL + '/friend/apply';
  return axios.post(url, data);
}

// 好友申请列表
api.friendApplyList = function(data) {
  var url = baseURL + '/friend/apply/list';
  return axios.post(url, data);
}

// 好友申请状态修改
api.friendApplyUpdate = function(data) {
  var url = baseURL + '/friend/apply/update';
  return axios.post(url, data);
}

export default api;

